#include "BaseDialog.h"
#include<QRegion>
#include <qrandom.h>
#include <QPainter>
#include <QRect>

namespace UserManagementSystem {

BaseDialog::BaseDialog(QWidget *parent,QPoint pos,QSize size)
    :QDialog(parent)
{

    //设置无边框，透明背景
    this->setAttribute(Qt::WA_TranslucentBackground);
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::Window|Qt::CustomizeWindowHint);

    //设置工具窗口的高度
    this->setMinimumSize(size);
    //主布局
    m_mainLayout=new QVBoxLayout(this);
    m_btnsLayout=new QHBoxLayout();
    m_titleLayout=new QHBoxLayout();


    //初始化
    m_titleLabel=new QLabel(tr("编辑患者"),this);
    m_contentWidget=new QWidget(this);
    m_cancleBtn=new QPushButton(tr("取消"),this);
    m_comfirmBtn=new QPushButton(tr("确认"),this);

    InitDefaultLayout();

    //绑定信号槽,取消按钮对应关闭窗口
    connect(m_cancleBtn,&QPushButton::clicked,this,[this](){
        this->close();
        emit closeWidget();
    });

    //绑定确认信号
    connect(m_comfirmBtn,&QPushButton::clicked,this,&BaseDialog::comfirm_signal);
}

void BaseDialog::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    painter.setRenderHint(QPainter::Antialiasing);

    QColor white(255,255,255);//带透明度的蓝色
    painter.setBrush(white);
    painter.setPen(Qt::NoPen);
    painter.drawRoundedRect(this->rect(),20,20);
}


QWidget *BaseDialog::GetContentWindow() const
{
    return m_contentWidget;
}

QHBoxLayout *BaseDialog::GetTitleLayout() const
{
    return m_titleLayout;
}

void BaseDialog::InitDefaultLayout()
{
    m_contentWidget->adjustSize();


    m_titleLayout->addWidget(m_titleLabel);
    m_titleLayout->addStretch(1);//添加一个弹簧

    m_btnsLayout->addWidget(m_cancleBtn);
    m_btnsLayout->addWidget(m_comfirmBtn);

    m_mainLayout->addLayout(m_titleLayout);
    m_mainLayout->addWidget(m_contentWidget);
    m_mainLayout->addStretch(3);
    m_mainLayout->addLayout(m_btnsLayout);

    //布局靠上
    m_mainLayout->setAlignment(Qt::AlignTop);

    InitDefaultStyle();
}

void BaseDialog::InitDefaultStyle()
{
    //白色
    QString style=R"(
        background-color: white;
        border: 1px solid black;
        border-radius: 15px;
        padding: 0px ;
    )";
    this->setStyleSheet(style); // 半透明灰色

    m_contentWidget->setStyleSheet("background-color: rgb(240,240,240);border: none;border-radius: 0px;");
    m_cancleBtn->setFixedHeight(30);
    m_comfirmBtn->setFixedHeight(30);

    QString font="font-size:16px;font-weight:bold;";
    m_titleLabel->setStyleSheet(font);

    //设置按钮的样式，
    //取消按钮是白底蓝字，确认按钮是蓝底白色
    QString cancle_sty=R"(
    QPushButton {
        background-color: none;       /* 背景白色 */
        color: #4672C4 ;                   /* 字体颜色蓝色 */
        border: 1px solid #4672C4;         /* 边框颜色蓝色，粗细2px */
        border-radius: 15px;            /* 圆角半径 10px，可根据需要调整 */
        padding: 5px 10px;              /* 内边距，避免文字贴边 */
    }
    QPushButton:hover,QPushButton:pressed{
        background-color: #5980ca;      /* 鼠标悬停时的背景色，可选 */
    }
    )";

    QString comfirm_sty=R"(
    QPushButton {
        background-color: #4672C4 ;       /* 背景白色 */
        color: white;                   /* 字体颜色蓝色 */
        border: 1px solid #4672C4;         /* 边框颜色蓝色，粗细2px */
        border-radius: 15px;            /* 圆角半径 10px，可根据需要调整 */
        padding: 5px 10px;             /* 内边距，避免文字贴边 */
    }
    QPushButton:hover,QPushButton:pressed{
        background-color: #5980ca;      /* 鼠标悬停时的背景色，可选 */
    }
    )";

    //为btn设置样式
    m_cancleBtn->setStyleSheet(cancle_sty);
    m_comfirmBtn->setStyleSheet(comfirm_sty);

}

};

